import { getMongoRepository } from "typeorm";
import { System_function } from "../models/SystemFunction";

class SystemFunctionService {

  // 查找全部
  findAll() {
    const systemFunctionService = getMongoRepository(System_function)
    return systemFunctionService.find()
  }

  // 根据id查找
  findById(id: string) {
    const systemFunctionService = getMongoRepository(System_function)
    return systemFunctionService.findOne(id)
  }

  // 修改状态
  updateState(id: string, state: boolean) {
    const systemFunctionService = getMongoRepository(System_function)
    return systemFunctionService.update(id, { state })
  }

  // 根据角色、类型查找
  findByRoleAndType(role: number, type: string) {
    const systemFunctionService = getMongoRepository(System_function)
    return systemFunctionService.findOne({role, type})
  }
}

export default new SystemFunctionService()